#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:pengfeifu
@file: day_02_format.py.py 
@version:
@time: 2021/11/04 
@email:1324734112@qq.com
@desc： 字符串格式化,适合模板
@function：常用函数
"""

# 字符串格式化
code = "2342"
txt = "您好，未来科技给您的验证码是：{}\n打死也不要告诉别人哦"
print(txt.format(code))

# 数字格式化,自动格式化
price = 52.2382
txt = "The price is {:.2f} dollars"
print(txt.format(price))

# format可以匹配多个参数
quantity = 3
itemno = 567
price = 52
myorder = "I want {} pieces of item number {} for {:.2f} dollars."
print(myorder.format(quantity, itemno, price))

# format可以指定位置顺序，您可以使用索引号（花括号 {0} 内的数字）来确保将值放在正确的占位符中：
quantity = 3
itemno = 567
price = 52
myorder = "I want {0} pieces of item number {1} for {2:.2f} dollars."
print(myorder.format(quantity, itemno, price))

# format 您还可以通过在花括号 {carname} 中输入名称来使用命名索引，但是在传递参数值 txt.format(carname = "Ford") 时，必须使用名称：
myorder = "I have a {carname}, it is a {model}."
print(myorder.format(carname="Porsche", model="911"))

# \表示字符转义
print('what\'s your name?')
